package accueil.pack;

import android.content.Context;
import chemin.pack.R;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import chemins.pack.CheminActivity;

/**
 *
 * @author isen
 */
public class Switcher extends View implements View.OnTouchListener {

    String[] liste;
    String value;
    int valueId;
    TextView textView1,textView2,textView3;
    String position;
    ImageView imageView;
    
    float y, oldY;
    
    public Switcher(Context context, AttributeSet attrs, ImageView imageView)
    {
        super(context, attrs);


        float Y = 0, oldY=0;
        this.imageView = imageView;
        Log.i("Switch","Imageview = " + imageView);
        
        this.position="down";
        changePosition("up");
        
        setFocusable(true);
	setFocusableInTouchMode(true);
	this.setOnTouchListener(this);
        

    }


    public void changePosition( String mouvement)
    {

        
        Log.i(" mouvement","mouvement =" + mouvement);
        
        if ((mouvement.equals("up"))&&(position.equals("down")))
        {
            position = "up";
            Log.i("Switch","Imageview = " + imageView);
            ((ImageView)imageView).setImageResource(R.drawable.switch_up);
                    
            
        }
        if ((mouvement.equals("down"))&&(position.equals("up")))
        {
            position = "down";
            Log.i("Switch","Imageview = " + imageView);
            ((ImageView)imageView).setImageResource(R.drawable.switch_down);
        }
       


        
    }
    
    public boolean onTouch(View view, MotionEvent event) {
        
        
        
        if ((event.getActionMasked () == event.ACTION_DOWN)||(event.getActionMasked () == event.ACTION_UP))
        {
           oldY = event.getY(0);
           y = event.getY(0);
        }
        
        
        if (event.getActionMasked () == event.ACTION_MOVE)
        {
           y = event.getY(0);
        }
        
        if ((int)((y-oldY)/20) > 1)
        {
            changePosition("down");
            oldY=y;
        }
        if ((int)((y-oldY)/20) < -1)
        {
            changePosition("up");
            oldY=y;
        }
        
        
        
        
        return true;
    }


}
